package com.example.seckill;

import com.example.seckill.utils.RedisFactory;
import redis.clients.jedis.Jedis;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: caowj1217
 * @Date: 2021/8/9上午10:05
 * @Description:
 */
public class SecKillImpl implements SecKillInterface {

    static Map<Long,Long> inventory;

    static {
        inventory = new HashMap<>();
       inventory.put(10000001L, 500L);
       inventory.put(10000002L, 10000L);
    }
    @Override
    public void secKill(String userID, Long productID) {
        //最简单的秒杀，这里仅作为demo示例
        if (inventory.get(productID) == 0){
            System.out.println("商品已经被抢完了");
        }
        Long productNum = reduceInventory(productID);
        System.out.println(userID + "成功抢到了" + productID + "商品,如今库存还剩下"+ productNum);
    }

    public Long reduceInventory(Long commodityId){
       inventory.put(commodityId,inventory.get(commodityId) - 1);
       return inventory.get(commodityId);
   }

}
